--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_CPT_CATEG AS (SELECT * FROM &erp.CPT_CATEG WHERE 1=2);




DELETE FROM se_CPT_CATEG;

 INSERT INTO se_CPT_CATEG
 (SELECT id categ_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle categ_lib,
         NULL categ_lib2,
         'T' tiers_typ
    FROM uv_ccatcpta) ;

 UPDATE se_CPT_CATEG tf SET enreg_id=(select enreg_id FROM &erp.CPT_CATEG f WHERE f.categ_cod=tf.categ_cod) ;
 UPDATE se_CPT_CATEG tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('categ_cod','CPT_CATEG','O') ;

 commit;



select * from (
SELECT &outils.stragg(source) source,categ_cod, enreg_id, enreg_s, categ_lib, categ_lib2, tiers_typ
FROM (
  SELECT 'uv' source ,g.* FROM se_CPT_CATEG g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.CPT_CATEG g
  )
GROUP BY categ_cod, enreg_id, enreg_s, categ_lib, categ_lib2, tiers_typ
HAVING Count(1)!=2) r
ORDER BY categ_cod;